home *** CD-ROM | disk | FTP | other *** search
/ Computer Inter@ctive 16 / Computer Interactive cdrom 16 - dic 98.iso / zdnetit / content / CLASSBLD.ZIP / Include / CB_CriticalSection.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-12-24  |  956 b   |  50 lines

  1. #ifndef CB_CRITICAL_SECTION
  2. #define CB_CRITICAL_SECTION
  3.  
  4. // This is Windows specific, need to change this for other platforms.
  5. #include <windows.h>
  6. #include <process.h>
  7.  
  8. class CriticalSection
  9. {
  10. private:
  11.     CRITICAL_SECTION _criticalSection;
  12.  
  13. public:
  14.     CriticalSection()
  15.     {
  16.         InitializeCriticalSection(&_criticalSection);
  17.     }
  18.     ~CriticalSection()
  19.     {
  20.         DeleteCriticalSection(&_criticalSection);
  21.     }
  22.  
  23.     void Enter()
  24.     { 
  25.         EnterCriticalSection(&_criticalSection); 
  26.     }
  27.     void Leave()
  28.     { 
  29.         LeaveCriticalSection(&_criticalSection); 
  30.     }
  31. };
  32.  
  33. class CriticalSectionLock
  34. {
  35. private:
  36.     CriticalSection& _criticalSection;
  37.  
  38. public:
  39.     CriticalSectionLock(CriticalSection& criticalSection)
  40.         : _criticalSection(criticalSection) 
  41.     { 
  42.         _criticalSection.Enter();
  43.     }
  44.     ~CriticalSectionLock()
  45.     {
  46.         _criticalSection.Leave();
  47.     }
  48. };
  49.  
  50. #endif